﻿using UnityEngine;

namespace DL
{
    public class Scout : MonoBehaviour,IExpert
    {
        private GameBlackboard m_GameBlackboard;
        private GameBlackboardKey m_IsSafeKey;

        private bool m_IsDangerSensor;

        private void Start()
        {
            m_GameBlackboard = GetComponent<GameBlackboardController>().GameBlackboard();
            
            m_IsSafeKey = m_GameBlackboard.GetOrRegistry("m_IsSafeKey");
        }

        public int GetInsistence(GameBlackboard gameBlackboard)
        {
            return m_IsDangerSensor ? 100 : 0;
        }

        public void Execute(GameBlackboard gameBlackboard)
        {
            gameBlackboard.AddAction(() =>
            {
                if (gameBlackboard.TryGetValue(m_IsSafeKey, out bool isSafe))
                {
                    gameBlackboard.SetValue(m_IsSafeKey,!isSafe);
                    Debug.Log($"当前最新值{m_IsSafeKey}:{!isSafe}");
                }
            });
        }

        private void Update()
        {
            // if (Keyboard.current.qKey.wasPressedThisFrame)
            // {
            //     if(m_GameBlackboard.TryGetValue(m_IsSafeKey,out bool isSafe))
            //     {
            //         m_GameBlackboard.SetValue(m_IsSafeKey,!isSafe);
            //         Debug.Log($"IsSafe ;{isSafe}");
            //     }
            // }

        }
    }
}